<template>
  <div>
    <!-- B端订单审核确认-->
    <TopFilter ref="topfrom" :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110" @resetChange="resetChange"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTables
        ref="table"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        columnsRef="OrderAuditConfirmSideB"
        :isSelectColumn="true"
        :onRowSelectChange="selectChangeHandle"
        :onColumnsChange="(columns) => (this.columns = columns)"
      >
        <template slot="controls" >
          <multiuse-button size="small" type="primary" :click="addHandle.bind(this, 1)" :disabled="isOpen">审核通过</multiuse-button>
          <multiuse-button size="small" type="primary" :click="addHandle.bind(this, 2)" :disabled="isOpen">作废</multiuse-button>
          <multiuse-button size="small" type="primary" :click="addHandle.bind(this, 3)" :disabled="isOpen">取消订单</multiuse-button>
          <multiuse-button size="small" type="primary" :click="addHandle.bind(this, 4)">导 出</multiuse-button>
          <multiuse-button size="small" type="primary" :click="addHandle.bind(this, 5)">导入发运通知</multiuse-button>
          <multiuse-button size="small" type="primary" :click="addHandle.bind(this, 6)" :disabled="isOpen">资金调整</multiuse-button>
          <multiuse-button size="small" type="primary" :click="addHandle.bind(this, 7)" :disabled="isOpen">地址调整</multiuse-button>
          <multiuse-button size="small" type="primary" :click="addHandle.bind(this, 8)" :disabled="isOpen">保 存</multiuse-button>
        </template>
      </FilterTables>
    </Spin>

    <BaseDialog :visible.sync="issearch" :title="'经销商查询'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ownerSeacher @close="dealercloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="isAddress" :title="'地址调整'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <AddressAdjustment @close="AddressClose" :list="selectList" />
    </BaseDialog>
    <BaseDialog :visible.sync="isFundType" :title="'资金类型调整'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <FundTypeAdjustment @close="FundTypeClose" :list="selectList" />
    </BaseDialog>
    <Drawer :visible.sync="detailVisible" :title="'订单信息'" :width="'80%'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <detailModel :rowData="formData" @close="emitcloseHandler" />
    </Drawer>
    <BaseDialog :visible.sync="isreject" :title="'审批驳回'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <reject :list="selectList" @close="rejectClose" />
    </BaseDialog>
    <BaseDialog :visible.sync="isFinanceReject" :title="'作废订单'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <FinanceReject :list="selectList" @close="financeRejectClose" />
    </BaseDialog>
    <BaseDialog :visible.sync="isImport" :title="'导入发运通知'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <importFiles @close="importcloseHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import { getList, postconfirmPass, saveList, cancelOrder, allAccountType, vehicleConfiguration, exportList, exporturl 
} from '@/api/omSale/OrderManagement/OrderAuditConfirmSideB';
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils';
import { region } from '@/api/cms-common/region';
import { getSaleAreaInfo } from '@/api/cms-common/dealerdata/index';
import { dealerCommon } from '@/api/cms-api/origin/commonDealerType';
import detailModel from './detailModel';
import ownerSeacher from './ownerSeacher';
import reject from './reject';
import FinanceReject from './FinanceReject';
import AddressAdjustment from './AddressAdjustment';
import FundTypeAdjustment from './FundTypeAdjustment';
import importFiles from './importFiles';
export default {
  name: 'OrderAuditConfirmSideB',
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: getList,
      fetchParams: {
      },
      exportLoading: false,
      formData: {},
      issearch: false,
      detailVisible: false,
      selectList: [],
      isOpen: true,
      isreject: false,
      isFinanceReject: false,
      isAddress: false,
      isFundType: false,
      isImport: false,
      areaList: []
    };
  },
  components: {
    ownerSeacher,
    detailModel,
    reject,
    FinanceReject,
    AddressAdjustment,
    FundTypeAdjustment,
    importFiles
  },
  mixins: [dictionary,region,dealerCommon ],
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    //初始化产品相关数据
    this.getvehicleList();
    //获取所有资金类型
    this.getAllAccountType();
    //初始化销售战区
    this.getAreaData();
    //初始化省份信息
    this.initProvince();
  },
  methods: {
    AddressClose(val) {
      if (val) {
        this.isOpen = true;
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
      this.isAddress = false;
    },
    FundTypeClose(val) {
      if (val) {
        this.isOpen = true;
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
      this.isFundType = false;
    },
    //初始化销售战区信息
    async getAreaData() {
      const res = await getSaleAreaInfo(15061016);
      if (res.resultCode === 200) {
        this.areaList = res.data;
        res.data.map((x) => {
          this.topFilterList.find((item) => item.fieldName == 'areaId').itemList.push({ text: x.orgName, value: x.id });
        });
      }
    },
    //获取战区名称
    getareaName(value) {
     if (this.areaList.length > 0) {
        for (let i in this.areaList) {
        if (this.areaList[i].id === value) {
          return this.areaList[i].orgName;
        }
      }
     }
    },
    //初始化所在省份
    async initProvince() {
      let pl = this.createRegionList();
      this.topFilterList.find((item) => item.fieldName == 'provinceId').itemList = pl;
    },
    //初始化所在市数据
    async initCity(provinceId) {
      //清空市
      this.topFilterList.find((item) => item.fieldName == 'provinceId').initialValue = '';
      if (!provinceId || provinceId == null || typeof provinceId == 'undefined') {
        return;
      }
      //取省数据
      let rd = this.getRegionData();
      this.cityData = rd[provinceId].children;
      let cl = this.createSubRegionList(this.cityData);
      this.topFilterList.find((item) => item.fieldName == 'cityId').itemList = cl;
    },
    // 获取车型车系
    async getvehicleList() {
      let res = await vehicleConfiguration(0, { isUnlimited: 10041001 });
      this.topFilterList.find((item) => item.fieldName === 'brandProductList').itemList = res.data;
    },
    //相关金额修改
    changeNum(index, data) {
      let discountAmount = 0;
      let sapPromotionPriceA = 0;
      let sapPromotionPriceB = 0;
      let sapServiceBonus = 0;
      let sapTerminalBonus = 0;
      let sapStandardPrice = 0;
      let singleRebateAmount = 0;
      let tryDriveDiscountRate = 0;
      discountAmount = Object.is(Number(data.discountAmount), NaN) ? 0 : Number(data.discountAmount);
      sapPromotionPriceA = Object.is(Number(data.sapPromotionPriceA), NaN) ? 0 : Number(data.sapPromotionPriceA);
      sapPromotionPriceB = Object.is(Number(data.sapPromotionPriceB), NaN) ? 0 : Number(data.sapPromotionPriceB);
      sapServiceBonus = Object.is(Number(data.sapServiceBonus), NaN) ? 0 : Number(data.sapServiceBonus);
      sapTerminalBonus = Object.is(Number(data.sapTerminalBonus), NaN) ? 0 : Number(data.sapTerminalBonus);
      singleRebateAmount =Object.is(Number(data.singleRebateAmount), NaN)?0:Number(data.singleRebateAmount);
      sapStandardPrice = Object.is(Number(data.sapStandardPrice), NaN) ? 0 : Number(data.sapStandardPrice);
      tryDriveDiscountRate = Object.is(Number(data.tryDriveDiscountRate), NaN) ? 0 : Number(data.tryDriveDiscountRate);
      data.sapSettlementPrice =
        sapStandardPrice +
        sapServiceBonus +
        sapPromotionPriceB +
        sapPromotionPriceA +
        discountAmount +
        sapTerminalBonus +
        singleRebateAmount -
        (sapStandardPrice * (tryDriveDiscountRate / 100)).toFixed(2);
    },
    //修改收车地址
    changeDealerAddress(value,row) {
      for (let address of row.addressDtos) {
        if(address.addressId == value) {
          // row.deliveryCityName = address.cityName;
          row.linkMan = address.linkMan;
          row.linkPhone = address.linkPhone;
          return;
        }
      }
    },
    //获取所有资金类型
    async getAllAccountType() {
      let res = await allAccountType();
      let accountTypeList = res.data.map((x) => ({ text: x.accountTypeName, value: x.accountId }));
      this.topFilterList.find((x) => x.fieldName == 'accountId').itemList = accountTypeList;
    },
    selectChangeHandle(row) {
      if (row.length > 0) {
        this.selectList = row || [];
        this.isOpen = false;
      } else {
        this.selectList = [];
        this.isOpen = true;
      }
      console.log('选中',this.selectList);
    },
    seacherFun() {
      this.issearch = true;
    },
    async addHandle(type) {
      var deliveryOrderIdList = [];
      if (type == 1) {
        //通过订单
        // //待审核和厂端取消可以继续审核
        let isForbidden = false;
        this.selectList.map(x => {
          if (x.orderStatus != 24151001 && x.orderStatus != 24151008) {
            isForbidden = true;
          }
        });
        if(isForbidden) {
           this.$notify({
            title: '警告',
            message: '选中订单存在非待审核状态或非厂端取消状态订单',
            type: 'warning',
          });
          return;
        }
        await this.$confirm('是否审核通过?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(async () => {
            //获取选中销售订单id
            for (let i = 0; i < this.selectList.length; i++) {
              deliveryOrderIdList[i] = this.selectList[i].id;
            }
            let res = await postconfirmPass({deliveryOderIdes: deliveryOrderIdList});
            if (res.resultCode == 200) {
              this.$notify({
                title: res.data,
                message: res.errMsg,
                type: 'success',
              });
              this.isOpen = true;
              this.fetchParams = Object.assign({}, this.fetchParams);
            }
          })
          .catch(() => {});
      } else if (type == 2) {
        //订单作废
        if (this.selectList.length > 1) {
          this.$notify({
            title: '警告',
            message: '只能对单条数据作废操作',
            type: 'warning',
          });
          return;
        }
        //待审核和厂端取消可以进行作废
        let isForbidden = false;
        this.selectList.map(x => {
          if (x.orderStatus != 24151001 && x.orderStatus != 24151008) {
            isForbidden = true;
          }
        });
        if(isForbidden) {
           this.$notify({
            title: '警告',
            message: '选中订单存在非待审核状态或非厂端取消状态订单',
            type: 'warning',
          });
          return;
        }
        //驳回订单
         if (this.selectList[0].firstFinanceCheckDate !== null && this.selectList[0].firstFinanceCheckDate !== '') {
          this.isFinanceReject = true;
        } else {
          this.isreject = true;
        }
      } else if (type == 3) {
         //取消订单
        //取消订单 发到sap后才能取消
        let isForbidden = false;
        this.selectList.map(x => {
          if (x.orderStatus != 24151002 && x.orderStatus != 24151009) {
            isForbidden = true;
          }
        });
        if(isForbidden) {
            this.$notify({
              title: '警告',
              message: '选中订单存在非已审核状态或非SAP取消结算状态订单',
              type: 'warning',
            });
            return;
          } 
        await this.$confirm('是否确定取消订单?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(async () => {
            //获取选中销售订单id
            for (let i = 0; i < this.selectList.length; i++) {
              deliveryOrderIdList[i] = this.selectList[i].id;
            }
            let res = await cancelOrder({deliveryOderIdes: deliveryOrderIdList});
            if (res.resultCode == 200) {
              this.$notify({
                title: res.data,
                message: res.errMsg,
                type: 'success',
              });
              this.isOpen = true;
              this.fetchParams = Object.assign({}, this.fetchParams);
            }
          })
          .catch(() => {});
      } else if (type == 4) {
        // let json = Object.assign({}, { CODE: 'CODE_0000038' }, this.fetchParams);
        // let res = await exporturl(json);
        // if (res.resultCode == 200) {
        //   this.$router.push('/admin/auth/oem/downloadCenter');
        // }

       this.$refs.topfrom.SUBMIT_FORM();

        this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
          confirmButtonText: '下载',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            let json = this.fetchParams;
            this.exportLoading = true;
            exportList(json)
              .then(response => {
                exportExcelFile(response.data, 'B端订单审核确认');
                this.exportLoading = false;
              })
              .catch(err => {
                console.log(err);
              });
          })
          .catch(() => {
            console.log('456');
            this.$message({
              type: 'info',
              message: '已取消'
            });
          });
      } else if (type == 5) {
        //导入发运通知
        this.isImport = true;
      } else if (type == 6) {
        //资金调整
        //待审核和厂端取消可以调整资金
        let isForbidden = false;
        this.selectList.map(x => {
          if (x.orderStatus != 24151001 && x.orderStatus != 24151008) {
            isForbidden = true;
          }
        });
        if(isForbidden) {
           this.$notify({
            title: '警告',
            message: '选中订单存在非待审核状态或非厂端取消状态订单',
            type: 'warning',
          });
          return;
        }
        let array = [],
        data = {};
        this.selectList.map((x) => {
          data[x.dealerCode] = x.dealerCode;
        });
        for (let i in data) {
          array.push(data[i]);
        }
        if (array.length > 1) {
          this.$notify({
            title: '警告',
            message: '请选择同一经销商的数据',
            type: 'warning',
          });
          return;
        } else {
          this.isFundType = true;
        }
      } else if (type == 7) {
        //地址调整
        //待审核和厂端取消可以调整收车地址
        let isForbidden = false;
        this.selectList.map(x => {
          if (x.orderStatus != 24151001 && x.orderStatus != 24151008) {
            isForbidden = true;
          }
        });
        if(isForbidden) {
           this.$notify({
            title: '警告',
            message: '选中订单存在非待审核状态或非厂端取消状态订单',
            type: 'warning',
          });
          return;
        }
        let array = [],
        data = {};
        this.selectList.map((x) => {
          data[x.dealerCode] = x.dealerCode;
        });
        for (let i in data) {
          array.push(data[i]);
        }
        if (array.length > 1) {
          this.$notify({
            title: '警告',
            message: '请选择同一经销商的数据',
            type: 'warning',
          });
          return;
        } else {
          this.isAddress = true;
        }
      } else if (type == 8) {
        //保存
        let isForbidden = false;
        let tryDriveDiscountcheck = false;
        let errorDoNoList = [];
        let sapSettlementPricecheck = false;
        let errorDoNoList1 = [];
        this.selectList.map(x => {
          if (x.orderStatus != 24151001 && x.orderStatus != 24151008) {
            isForbidden = true;
          }
          if (!/^(?!00)(?:[0-9]{1,2}|100)$/.test(x.tryDriveDiscountRate)) {
             console.log(!/^(?!00)(?:[0-9]{1,2}|100)$/.test(x.tryDriveDiscountRate));
            console.log(x.tryDriveDiscountRate);
            tryDriveDiscountcheck = true;
            errorDoNoList.push(x.doNo);
          }
          if (x.sapSettlementPrice < 0) {
            sapSettlementPricecheck = true;
            errorDoNoList1.push(x.doNo);
          }
        });
        if(isForbidden) {
           this.$notify({
            title: '警告',
            message: '选中订单存在非待审核状态或非厂端取消状态订单',
            type: 'warning',
          });
          return;
        }
       //试乘试驾折扣校验
       if(tryDriveDiscountcheck) {
            this.$notify({
            title: '警告',
            message: '订单{' + errorDoNoList + '}未通过校验,试乘试驾折扣需设置为0-100',
            type: 'warning',
          });
          return;
        }
       //结算价格校验
       if(sapSettlementPricecheck) {
            this.$notify({
            title: '警告',
            message: '订单{' + errorDoNoList1 + '}未通过校验,试乘试驾折扣需设置为0-100',
            type: 'warning',
          });
          return;
        }
        await this.$confirm('是否保存选定的数据?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(async () => {
            console.log(this.selectList);
            for (let i = 0; i < this.selectList.length; i++) {
              deliveryOrderIdList[i] = this.selectList[i].id;
              if (this.selectList[i].addressDtos.length > 0) {
                this.selectList[i].address = this.selectList[i].addressDtos
                .find(x => x.addressId == this.selectList[i].addressId).address;
              }
            }
            let res = await saveList(this.selectList);
            if (res.resultCode == 200) {
              this.$notify({
                title: res.data,
                message: res.errMsg,
                type: 'success',
              });
              this.isOpen = true;
              this.fetchParams = Object.assign({}, this.fetchParams);
            }
          })
          .catch(() => {});
      }
    },
    changeHandle(params) {
      this.isOpen = true;
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    editHandle(data) {
      this.formData = data;
      this.detailVisible = true;
    },
    emitcloseHandler(val) {
      if (val) {
        this.isOpen = true;
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
      this.detailVisible = false;
    },
    rejectClose(val) {
      if (val) {
        this.isOpen = true;
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
      this.isreject = false;
    },
    financeRejectClose(val) {
      if (val) {
        this.isOpen = true;
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
      this.isFinanceReject = false;
    },
    dealercloseHandler(val, data) {
      if (data) {
        let dealerCodes = [];
        data.map((x) => {
          dealerCodes.push(x.dealerCode);
        });
        this.topFilterList.find((x) => x.fieldName == 'dealerCodes').initialValue = dealerCodes.toString();
      }
      this.issearch = false;
    },
    importcloseHandler() {
      this.isImport = false;
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    resetChange(val) {
      this.topFilterList.map((x) => {
        if (x.fieldName == 'officeId') {
          x.itemList = [];
        }
      });
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    checkRow(checked, item) {
      console.log(`checked:${checked}`);
      console.log(`item:${item}`);
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '订单编号',
          fieldName: 'orderNo',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '物料编码',
          fieldName: 'productCode',
          placeholder: '请输入',
        },
        {
          type: 'SELECT',
          label: '订单类型',
          fieldName: 'orderType',
          placeholder: '请选择',
          itemList: this.createDictList('2105'),
        },
        {
          type: 'SELECT',
          label: '订单明细状态',
          fieldName: 'orderStatus',
          placeholder: '请选择',
          itemList: this.createDictList('2415'),
        },
        {
          type: 'SELECT',
          label: '车辆用途',
          fieldName: 'vehicleUse',
          placeholder: '请选择',
          itemList: this.createDictList('2416'),
        },
        {
          type: 'SELECT',
          label: '紧急度',
          fieldName: 'emergencyType',
          placeholder: '请选择',
          itemList: this.createDictList('2101'),
        },
        {
          type: 'SELECT',
          label: '资金类型',
          fieldName: 'accountId',
          placeholder: '请选择',
          itemList: [],
        },
        {
          type: 'INPUT_CASCADER',
          label: '车型选择',
          fieldName: 'brandProductList',
          placeholder: '请选择',
          options: { titles: ['品牌', '车系', '车型', '配置', '选装', '颜色'] },
          itemList: [],
        },
        { 
          type: 'SELECT', 
          label: 'B端战区', 
          fieldName: 'areaId', 
          placeholder: '请选择',  
          itemList: [] 
        },
        {
          type: 'SELECT',
          label: '省份',
          fieldName: 'provinceId',
          placeholder: '请选择',
          itemList: [],
          change: (value) => {
            this.initCity(value);
          },
        },
        { 
          type: 'SELECT', 
          label: '城市', 
          fieldName: 'cityId', 
          placeholder: '请选择', 
          itemList: [] 
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '经销商编码',
          fieldName: 'dealerCode',
          placeholder: '请输入',
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 2)}>
                  详情
                </multiuse-button>
              </div>
            );
          },
        },
        {
          title: '是否最优先结算',
          dataIndex: 'firstPrioritySettle',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <el-checkbox disabled={true} checked={p.row.firstPrioritySettle === 10041001}></el-checkbox>;
          },
        },
        {
          title: '是否优先结算',
          dataIndex: 'prioritySettle',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <el-checkbox disabled={true} checked={p.row.prioritySettle === 10041001}></el-checkbox>;
          },
        },
        {
          title: 'B端战区',
          dataIndex: 'areaName',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (props) => {
            return <span>{
              this.getareaName(props.row.areaId)}</span>;
          }
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '订单编号',
          dataIndex: 'orderNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          align: 'center',
          width: 200,
        },
        {
          title: '订单管理号',
          dataIndex: 'doNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          align: 'center',
          width: 200,
        },
        {
          title: '订单类型',
          dataIndex: 'orderType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2105'),
          render: (p) => {
            return <span>{this.createDictText(p.row.orderType, '2105')}</span>;
          },
        },
        {
          title: '紧急度',
          dataIndex: 'emergencyType',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <span>{this.createDictText(p.row.emergencyType, '2101')}</span>;
          },
        },
        {
          title: '车辆用途',
          dataIndex: 'vehicleUse',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <span>{this.createDictText(p.row.vehicleUse, '2416')}</span>;
          },
        },
        {
          title: '订单明细状态',
          dataIndex: 'orderStatus',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: p => {
            return <span>{this.createDictText(p.row.orderStatus, '2415')}</span>;
          }
        },
        {
          title: '资金类型',
          dataIndex: 'accountId',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'select',
          editRequired: true,
          rules: [{ required: true, message: '请填写', trigger: 'blur' }],
          render: (p) => {
            return (
              <el-select
                size="mini"
                v-model={p.row.accountId}
                required
                placeholder="请选择"
                onChange={(value) => {
                  p.row.accountId = value;
                }}
              >
                {p.row.accountTypes.map((item) => (
                  <el-option key={item.accountId} label={item.accountTypeName} value={item.accountId} />
                ))}
              </el-select>
            );
          },
        },
        {
          title: '订单年月',
          dataIndex: 'orderYearMonth',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '运输方式',
          dataIndex: 'transportType',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <span>{this.createDictText(p.row.transportType, '2409')}</span>;
          },
        },
        {
          title: '收车地址',
          dataIndex: 'addressId',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'select',
          editRequired: true,
          rules: [{ required: true, message: '请填写', trigger: 'blur' }],
          render: (p) => {
            return (
              <el-select
                size="mini"
                v-model={p.row.addressId}
                required
                placeholder="请选择"
                onChange={(value) => {
                  p.row.addressId = value;
                  this.changeDealerAddress(value,p.row);
                }}
              >
                {p.row.addressDtos.map((item) => (
                  <el-option key={item.addressId} label={item.address} value={item.addressId} />
                ))}{' '}
              </el-select>
            );
          },
        },
        // {
        //   title: '送达城市',
        //   dataIndex: 'deliveryCityName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        // },
        {
          title: '联系人',
          dataIndex: 'linkMan',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '联系电话',
          dataIndex: 'linkPhone',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '物料编码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '物料描述',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '配置',
          dataIndex: 'configName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '选装',
          dataIndex: 'optionName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '内饰',
          dataIndex: 'trimName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '外饰',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '市场指导价',
          dataIndex: 'sapStandardPrice',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
        },
        {
          title: '基础折扣',
          dataIndex: 'discountAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          editRequired: true,
          defaultEditable: true,
          precision: 2,
          onInput: (index, data) => {
            this.changeNum(index, data);
          },
        },
        {
          title: '终端奖',
          dataIndex: 'sapTerminalBonus',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          editRequired: true,
          defaultEditable: true,
          precision: 2,
          onInput: (index, data) => {
            this.changeNum(index, data);
          },
        },
        {
          title: '优质服务奖',
          dataIndex: 'sapServiceBonus',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          editRequired: true,
          defaultEditable: true,
          precision: 2,
          onInput: (index, data) => {
            this.changeNum(index, data);
          },
        },
        {
          title: '促销1',
          dataIndex: 'sapPromotionPriceA',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          editRequired: true,
          defaultEditable: true,
          precision: 2,
          onInput: (index, data) => {
            this.changeNum(index, data);
          },
        },
        {
          title: '促销2',
          dataIndex: 'sapPromotionPriceB',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          editRequired: true,
          defaultEditable: true,
          precision: 2,
          onInput: (index, data) => {
            this.changeNum(index, data);
          },
        },
        {
          title: '试乘试驾折扣（%）',
          dataIndex: 'tryDriveDiscountRate',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'number',
          editPattern: /^(?!00)(?:[0-9]{1,2}|100)$/,
          editRequired: true,
          defaultEditable: true,
          onInput: (index, data) => {
            this.changeNum(index, data);
          },
        },
        {
          title: '结算价格',
          dataIndex: 'sapSettlementPrice',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
        },
        {
          title: '是否使用返利',
          dataIndex: 'isRebate',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: (p) => {
            return <span>{this.createDictText(p.row.isRebate, '1004')}</span>;
          },
        },
        {
          title: '返利使用金额',
          dataIndex: 'singleRebateAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '提报时间',
          dataIndex: 'reportDate',
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          filterType: 'date-range',
        },
        {
          title: '审核时间',
          dataIndex: 'checkDate',
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          filterType: 'date-range',
        },
        {
          title: '作废原因',
          dataIndex: 'checkRamark',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '审批报告编号',
          dataIndex: 'reportNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'input',
          defaultEditable: true,
        },
        {
          title: '发运须知',
          dataIndex: 'deliveryRamark',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'input',
          defaultEditable: true,
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          editType: 'input',
          defaultEditable: true,
        },
      ];
    },
  },
};
</script>
